home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Fixation 1.3
/
graphutil.c
< prev
next >
Wrap
Text File
|
1996-01-18
|
3KB
|
139 lines
// airborneutil.c
#include <QDOffscreen.h>
#include <stdlib.h>
#include <math.h>
#include "error.h"
#include "graphutil.h"
// allocates memory for a gworld and sets clip stuff
void makegworld(GWorldPtr *gw, Rect *bounds, int depth, CTabHandle dacolors)
{
GDHandle SaveGD;
CGrafPtr SavePort;
OSErr result;
int a;
GetGWorld(&SavePort, &SaveGD);
// note that all gworlds are kept local, which destroys
// graphics acceleration hardware
result = NewGWorld(gw, depth, bounds, dacolors, nil, keepLocal);
if (result) {
// stdmessage("\pSorry, not enough memory to start up.");
verify(false);
}
verify(gw);
a = LockPixels((*gw)->portPixMap);
verify(a);
SetGWorld(*gw, nil);
ClipRect(&(**gw).portRect);
PaintRect(&(**gw).portRect);
SetGWorld(SavePort, SaveGD);
}
// reads a texture as a PICT resource and copies it into given GWorld
void loadtexture(GWorldPtr gw, int id)
{
GDHandle SaveGD;
CGrafPtr SavePort;
Rect r;
PicHandle ph;
verify(gw);
ph = GetPicture(id);
verify(!ResError());
verify(ph);
r = (**ph).picFrame; // get rect of pict
verify(r.right > r.left);
GetGWorld(&SavePort, &SaveGD);
SetGWorld(gw, nil);
DrawPicture(ph, &r);
ReleaseResource((Handle) ph);
SetGWorld(SavePort, SaveGD);
}
// read in the pictures and store them in offscreen pixmaps
// starts at 128, masks at base + id
// goes until maxresid (if -1, go until hit blank)
void GetPixFromResources(short base, int numpix, Rect blockrect[],
GWorldPtr bpix[], GWorldPtr bmask[], CTabHandle dacolors)
{
Rect stdrect = {0, 0, 32, 32};
GDHandle SaveGD;
CGrafPtr SavePort;
int curid;
PicHandle p;
GetGWorld(&SavePort, &SaveGD);
curid = 0; // start here
// get other stuff
while (1) {
p = GetPicture(curid + base);
if (!p && numpix < 0)
break; // we done
if (!p)
blockrect[curid] = stdrect;
else
blockrect[curid] = (**p).picFrame;
OffsetRect(&blockrect[curid], -blockrect[curid].left, -blockrect[curid].top);
makegworld(&(bpix[curid]), &blockrect[curid], 8, dacolors);
if (p) {
// paint the picture into a pixmap, thus storing it that way
SetGWorld(bpix[curid], nil);
DrawPicture(p, &blockrect[curid]);
ReleaseResource((Handle) p);
}
// now get the mask, if it exists
if (bmask) {
p = GetPicture(curid + base + 1000);
if (!p) // no mask for this one
bmask[curid] = 0;
else {
makegworld(&(bmask[curid]), &blockrect[curid], 1, 0);
SetGWorld(bmask[curid], nil);
EraseRect(&blockrect[curid]);
DrawPicture(p, &blockrect[curid]);
ReleaseResource((Handle) p);
}
}
curid++;
if (numpix > 0 && curid >= numpix) // we done
break;
}
/* if (pgGameWindDepth != 8) {
// we now convert all pixmaps into the depth of the gamewindow
for (i=0;i<maxPix;i++) {
if (!bpix[i])
continue;
result = NewGWorld(&tempgw, 0, &blockrect[i], 0, nil, 0);
if (result)
seriousError(ePartitionTooSmall);
SetGWorld(tempgw, nil);
a = LockPixels(tempgw->portPixMap); verify(a);
ClipRect(&(*tempgw).portRect);
CopyBits ((BitMap *) *(bpix[i]->portPixMap), (BitMap *) *(tempgw->portPixMap),
&blockrect[i], &blockrect[i], srcCopy, nil);
UnlockPixels(bpix[i]->portPixMap);
DisposeGWorld(bpix[i]);
bpix[i] = tempgw;
tempgw = 0;
}
}
*/
SetGWorld(SavePort, SaveGD); // restore original world (save the Earth)
}